package eoeProject.edenOfEast.core;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;


import sun.misc.*;

public class PassDigest {
	private static  PassDigest instance = new PassDigest();

	public static PassDigest getInstance(){
		return instance;
	}

	PassDigest(){}

	 public String getPassDigest (String userName,String password){
	    String passDigest = null;
	    try	{
	    	if (password != null && 0 < password.length()) {
	    		MessageDigest md = MessageDigest.getInstance("SHA-1");
	    		md.update(userName.getBytes());
	    		md.update(password.getBytes());
	    		byte[] digest = md.digest();
	    		@SuppressWarnings("restriction")
				BASE64Encoder encoder = new BASE64Encoder();
	    		@SuppressWarnings("restriction")
				String b64digest = encoder.encodeBuffer(digest);
	    		passDigest = b64digest.trim();
	    	}
	    } catch (NoSuchAlgorithmException e) {
	    	System.out.println(
		        "PassDigestException: " + e.getMessage());
		}
	    return passDigest;
	 }

}
